<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>
<style>
.maskback{
	position:fixed;
	width:100%;
	height:100%;
	top:0px;
	background:rgba(0,0,0,0.7);
}
.mainback{
    width: 40%;
    height: 250px;
    background: #fff;
    margin: 0 auto;
    margin-top: 17%;
}
.maskbackf{
	position:fixed;
	width:100%;
	height:100%;
	top:0px;
	background:rgba(0,0,0,0.7);
}
.mainbackf{
    width: 60%;
    height: 300px;
    background: #fff;
    margin: 0 auto;
    margin-top: 10%;
}
.cke_chrome{
	    width: 95% !important;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">店主昵称</span>
        <input type="text" class="summer-input" id="userNickName"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">店主ID</span>
        <input type="text" class="summer-input" id="userId"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">手机号</span>
        <input type="text" class="summer-input" id="phone"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">推广位名称</span>
        <input type="text" class="summer-input" id="tgwName"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">推广位ID</span>
        <input type="text" class="summer-input" id="tgwId"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">推广位PID</span>
        <input type="text" class="summer-input" id="tgwPid"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">状态</span>
        <input type="text" class="summer-input" id="status" />
    </span>
    <span class="field-cont">
        <span class="field-cont-title">创建时间</span>
        <input type="text" class="summer-input" id="createTime"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/>
    </span>   
    <span class="field-cont">
        <span class="field-cont-title">-</span>
        <input type="text" class="summer-input" id="updateTime"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/>
    </span>
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="30%">
	    <col width="25%">
	    <col width="25%">
	    <col width="25%">
	    <col width="10%">
	    <col width="10%">
	    <col width="20%">
	    <col width="20%">
	    <col width="30%">
	    <thead>
		    <tr>
		        <th>推广位ID/名称/推广位PID</th>
		        <th>创建时间</th>
		        <th>手机号码</th>
		        <th>店主ID/昵称</th>
		        <th>类型</th>
		        <th>状态</th>
		        <th>开店失败原因</th>
		        <th>微信账号名称</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>
<div style="display: none" class="maskback">
     <div class="mainback">
     	 <div class="form-cont" style="top:40px;">
     	    <input type="hidden" name="id" id="id"/>
	        <p class="form-cont-title"><span class="field-required">*</span>推广位ID</p>
	        <input type="text" id="tgwIds" name="tgwIds" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-cont" style="top:40px;">
	        <p class="form-cont-title"><span class="field-required">*</span>推广位名称</p>
	        <input type="text" id="tgwNames" name="tgwNames" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-btn-wrapper" id="funcbar" style="margin-top: 100px;">
	        <a id="save" href="javascript:;" class="btn btn-ok btn-normal  wave distance-right" >保存</a>
	        <a class="btn btn-normal" id="backBtn">关闭</a>
	     </div>
     </div>
</div>
<div style="display: none" class="maskbackf">
     <div class="mainbackf">
     	 <div class="form-cont" style="top:40px;padding-left: 40px;">
     	 <input type="hidden" name="idd" id="idd"/>
	        <p>失败原因</p>
	        <textarea class="summer-textarea" id="failContents" name="failContents"></textarea>
	     </div>
	     <div class="form-btn-wrapper" id="funcbar" style="margin-top: 100px;">
	        <a id="savef" href="javascript:;" class="btn btn-ok btn-normal  wave distance-right" >保存</a>
	        <a class="btn btn-normal" id="backBtnf">关闭</a>
	     </div>
     </div>
</div>
<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL: basePath + "${common_url}del",
	   	EDIT: basePath + "${common_url}edit",
	   	FAIL: basePath + "${common_url}fail",
	   	EDIT_SAVE: basePath + "${common_url}editsave",
	   	INIT_SUCCESS: basePath + "${common_url}initSuccess",
	   	INIT_FAIL: basePath + "${common_url}initFail",
	   	RUZHU_SUCCESS: basePath + "${common_url}ruzhuSuccess",
	   	INIT: basePath + "${common_url}init"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	$('#status').combobox({
    		defaultValue : '0',
    		valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_USERS_OPEN_STORE_STATE'
        });
    	$('#type').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_USERS_OPEN_STORE_TYPE'
        });
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#userNickName').val('');
        	$('#userId').val('');
        	$('#phone').val('');
        	$('#tgwName').val('');
        	$('#tgwId').val('');
        	$('#tgwPid').val('');
        	$('#createTime').val('');
        	$('#updateTime').val('');
			$('#status').combobox('clear');
        	reloadTable();
        });
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD; 	  	
		});
        
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        //
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initSuccess"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	$(".maskback").show();
        	$("#id").val(id);
        });
        $("#backBtn").click(function(){
    		$(".maskback").hide();
        	window.location.href = CONST_URL.INIT; 	
    	});
        
        $("#save").on("click",function(){
    		var tgwId = $("#tgwIds").val();
    		var tgwName = $("#tgwNames").val();
    		var id = $("#id").val();
    		submit(id,tgwId,tgwName);
    	});
        
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initFail"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	//alert(id)
        	$(".maskbackf").show();
        	$("#idd").val(id);
        });
        
        $("#backBtnf").click(function(){
    		$(".maskbackf").hide();
    		window.location.href = CONST_URL.INIT; 	
    	});
        $("#savef").on("click",function(){
    		var failContents = $("#failContents").val();
    		var idd = $("#idd").val();
    		submitf(idd,failContents);
    	});
        
        //删除
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
		
        
    });
    
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"userNickName": trimSpace($('#userNickName').val()),
            		"userId": trimSpace($('#userId').val()),
            		"phone": trimSpace($('#phone').val()),
            		"tgwName": trimSpace($('#tgwName').val()),
            		"tgwId": trimSpace($('#tgwId').val()),
            		"tgwPid": trimSpace($('#tgwPid').val()),
            		"createTime": trimSpace($('#createTime').val()),
            		"updateTime": trimSpace($('#updateTime').val()),
            		"status":$('#status').combobox('getValue')
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"userNickName": trimSpace($('#userNickName').val()),
    				"userId": trimSpace($('#userId').val()),
            		"phone": trimSpace($('#phone').val()),
            		"tgwName": trimSpace($('#tgwName').val()),
            		"tgwId": trimSpace($('#tgwId').val()),
            		"tgwPid": trimSpace($('#tgwPid').val()),
            		"createTime": trimSpace($('#createTime').val()),
            		"updateTime": trimSpace($('#updateTime').val()),
            		"status":$('#status').combobox('getValue')
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<p>推广位ID：'+ rowData.tgwId +'</p>'
    		    		 		+'<p>推广位名称：'+rowData.tgwName+'</p>'
    		    		 		+'<p>推广位PID：'+rowData.tgwPid+'</p>';
    		    	 }
    		     },
    		     {
    		    	 field:'createTime'
    		     },
    		     {
    		    	 field: 'phone'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<p>店主ID：'+ rowData.userId +'</p>'+'<br/>'
    		    		 		+'<p>店主名称：'+rowData.userNickName+'</p>';
    		    	 }    		     },
    		     {
    		    	 field:'type'
    		     },
    		     {
    		    	 field:'status'
    		     },
    		     {
    		    	 field:'failContent'
    		     },
    		     {
    		    	 field:'weixinAccount'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 if(rowData.status == "审核中" || rowData.status == null || rowData.status == ""){
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 4,    //显示数量initEdit
        		    			 permit: ['${name_english}:initSuccess', '${name_english}:initFail','${name_english}:initEdit','${name_english}:del'] //需要的权限按钮
        		    		 });
    		    		 }
    		    		 if(rowData.status == "通过"){
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 3,    //显示数量
        		    			 permit: ['${name_english}:initEdit','${name_english}:del'] //需要的权限按钮
        		    		 });
    		    		 }
    		    		 if(rowData.status == "不通过"){
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 3,    //显示数量
        		    			 permit: ['${name_english}:initEdit','${name_english}:del'] //需要的权限按钮
        		    		 });
    		    		 }
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
    //表单提交
    function submit(id,tgwId,tgwName) {
        $.ajax({
           url: CONST_URL.RUZHU_SUCCESS,
     	   data:{"id":id,"tgwIds":tgwId,"tgwNames":tgwName},
     	   success:function(data){
     		   $.stip({
  	                type:'ok',//显示类型 有info、 ok、 danger
  	                text: '保存成功！',
  	                onBeforeHide: function () {
  	                	$(".maskback").hide();
  	  			        $("#"+tgwId).html('<div class="summer-datagrid-cell ">'+tgwId+'</div>');
  	  			    	$("#"+tgwName).html('<div class="summer-datagrid-cell ">'+tgwName+'</div>');
	                	reloadTable();  
  	               }
              	});
     	   }
        });
    }
    function submitf(idd,failContents) {
        $.ajax({
           url:basePath + "${common_url}fail",
     	   data:{"idd":idd,"failContents":failContents},
     	   success:function(data){
     		   $.stip({
  	                type:'ok',//显示类型 有info、 ok、 danger
  	                text: '保存成功！',
  	                onBeforeHide: function () {
  	                	$(".maskbackf").hide();
  	  			        $("#"+failContents).html('<div class="summer-datagrid-cell ">'+failContents+'</div>');
	                	reloadTable();  

  	               }
              	});
     	   }
        });
    }
  
</script>
</body>
</html>